from appium.webdriver.common.appiumby import AppiumBy
from Util.AppDriver import AppDriver


class BasePage:
    def __init__(self, driver):
        self.driver = driver

    def visit(self, url):
        self.driver.get(url)

    def locator(self, loc):
        return self.driver.find_element(*loc)

    def locators(self, loc):
        return self.driver.find_elements(*loc)

    def findelement(self, loc):
        return self.driver.find_element(*loc)

    def findelements(self, loc):
        return self.driver.find_elements(*loc)

    def click(self, loc):
        self.locator(loc).click()

    def input(self, loc, txt):
        self.locator(loc).send_keys(txt)

    def get_xpath(self, xpath):
        element = self.driver.find_element_by_xpath(xpath)
        return element

    def get_xpaths(self, xpath):
        element = self.driver.find_elements_by_xpath(xpath)
        return element

    def get_id(self, id):
        element = self.driver.find_element_by_id(id)
        return element

    def get_ids(self, ids):
        elements = self.driver.find_elements_by_id(ids)
        return elements

    def get_text_ui(self, uis):
        # self.driver.find_element_by_android_uiautomator('new UiSelector().textContains("{}")'.format(l)).click()
        elements = self.driver.find_element_by_android_uiautomator(uis)
        return elements

    def get_text_xpath(self, xpa):
        # self.driver.find_element_by_android_uiautomator('new UiSelector().textContains("{}")'.format(l)).click()
        elements = self.driver.find_element_by_xpath(xpa)
        return elements